
    /**  
    * @Title: PortalCustomDefServiceImpl.java
    * @Package com.efast.cafe.portal.service.company.impl
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2019年1月18日
    * @version V1.0  
    */
    
package com.efast.cafe.portal.service.company.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.cafe.framework.service.CafeServiceImpl;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.cafe.portal.dao.company.PortalCustomDefDao;
import com.efast.cafe.portal.entity.company.PortalCustomDef;
import com.efast.cafe.portal.service.company.PortalCustomDefService;
import com.efast.cafe.util.StringUtil;

import net.sf.json.JSONObject;
import tk.mybatis.mapper.entity.Example;

/**
    * @ClassName: PortalCustomDefServiceImpl
    * @Description: 用户个性化定制
    * @author Administrator
    * @date 2019年1月18日
    *
    */
@Service
public class PortalCustomDefServiceImpl extends CafeServiceImpl<PortalCustomDef> implements PortalCustomDefService {

	private PortalCustomDefDao portalCustomDefDao;

	@Autowired
	public void setPortalCustomDefDao(PortalCustomDefDao portalCustomDefDao) {
		this.portalCustomDefDao = portalCustomDefDao;
		this.mapper = portalCustomDefDao;
	}

	
	    
	@Override
	public void customDefByUser(PortalCustomDef def) {
		def.setCompanyCode(SpringWebUtils.getRequestCompany());
		def.setUsername(SpringWebUtils.getRequestUser());
		def.setDefValue(def.getDefValue());
		Example e = new Example(PortalCustomDef.class);
		Example.Criteria criteria = e.createCriteria();
		criteria.andEqualTo("defKey", def.getDefKey());
		criteria.andEqualTo("companyCode",def.getCompanyCode());
		criteria.andEqualTo("username", def.getUsername());
		PortalCustomDef cdef = portalCustomDefDao.selectOneByExample(e);
		if(cdef!=null){
			def.setLastUpdateTime(new Date());
			def.setId(cdef.getId());
			portalCustomDefDao.updateByExample(def, e);
		}else{
			def.setCreateTime(new Date());
			portalCustomDefDao.insert(def);
		}
	}



	@Override
	public List<PortalCustomDef> queryDef(PortalCustomDef def) {
		Example e = new Example(PortalCustomDef.class);
		Example.Criteria criteria = e.createCriteria();
		criteria.andEqualTo("companyCode",SpringWebUtils.getRequestCompany());
		criteria.andEqualTo("username", SpringWebUtils.getRequestUser());
		if(StringUtil.isNotBlank(def.getDefKey())){
			criteria.andEqualTo("defKey", def.getDefKey());
		}
		if(StringUtil.isNotBlank(def.getDefGroup())){
			criteria.andEqualTo("defGroup", def.getDefGroup());
		}
		return portalCustomDefDao.selectByExample(e);
	}
	
	
	
}
